# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2023-06-14
desc: 
sample: 
"""
import json

import jsonpath


def test_json_path():
    filetxt = ''
    with open("jsonpath.json", mode='r', encoding='utf-8') as f:
        filetxt = f.read()

    print(filetxt)
    books = json.loads(filetxt)
    checkurl = "$.store.bicycle.color"
    print(jsonpath.jsonpath(books, checkurl))
    # 绝对路径 多个
    print(jsonpath.jsonpath(books, '$.store.book[*].price'))
    # 第一个
    print(jsonpath.jsonpath(books, '$.store.book[0].price'))
    # 相对路径问题 。。
    print(jsonpath.jsonpath(books, '$..price'))  # 所有价格
    print(jsonpath.jsonpath(books, '$..book[*].price'))


if __name__ == '__main__':
    test_json_path()